package com.power.controller.DefectAd;

import com.alibaba.fastjson.JSONObject;
import com.power.ov.ResultData;
import com.power.service.DefectAdService;
import com.power.service.impl.defectAdServiceImpl;
import  com.power.common.Contants;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Arrays;

/**
 * Created/**
 * Created with IntelliJ IDEA.
 * User: lh
 * Date: 2020/10/04 17:18
 * Description:
 * Version: V1.0
 */
@WebServlet("/defectDel.do")
public class deleteDefect extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String defect_id = request.getParameter("defect_id");
        String defect_state=request.getParameter("state_name2");
        System.out.println(defect_state);
        System.out.println(defect_id);
        DefectAdService defectAdService = new defectAdServiceImpl();

        ResultData resultData = new ResultData<>();
        try {
            int result = defectAdService.delDefectById(defect_state,defect_id);
            if(result > 0){
                resultData.setCode(Contants.SUCCESS);
                resultData.setMsg("操作成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("系统繁忙，请联系管理员。");
        }
        //将对象封装成JSON数据返回
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(JSONObject.toJSONString(resultData));
        response.getWriter().flush();
        response.getWriter().close();

    }
}
